{%extends 'back.html' %}
{%block hello%}
    <div class="tpl-content-wrapper" style="margin-top: -7px;">
        <div class="tpl-content-page-title">
        </div>
        <div class="tpl-portlet-components" style="background-color: whitesmoke;">
            <div class="portlet-title">
                <div class="caption font-green bold">
                    <span class="am-icon-code"></span> 添加测试用用例
                </div>
                <div class="tpl-portlet-input tpl-fz-ml">
                    <div class="portlet-input input-small input-inline">
                        <div class="input-icon right">
                        </div>
                    </div>
                </div>
            </div>
            {% with messages = get_flashed_messages()%}
                {% if messages%}
                    <ul class='flashes'>
                        {% for message in messages %}
                            <li style="color:red">{{ message }}</li>
                        {% endfor %}
                    </ul>
                {% endif %}
            {% endwith %}
            <form method="POST" action="{{url_for('case.addtestcase')}}">
                {{form.hidden_tag()}}
                {{form.csrf_token}}
                <div>
                    <div class="form-group">
                        <strong>项目名字:</strong>
                        {% for project in  projects %}
                            <input type='radio' value="{{  project.project_name }}" name="project" class="projects" onclick="yilai()">
                            {{ project.project_name }}
                        {% endfor %}
                    </div>
                    <span>&nbsp;</span>
                    <div class="form-group">
                        <strong>模块名字:</strong>
                        <select name="mode">
                        {% for model in  models %}
                            <option>{{  model.model_name }}</option> 
                        {% endfor %}
                        </select>
                    </div>
                    <span>&nbsp;</span>
                    <div class="form-group">
                        <strong>接口:</strong>
                        <select name="interface_name">
                            {%for interfact in inrterface_list%}
                            <option>{{interfact.Interface_name}}</option>
                            {%endfor%}
                        </select>
                    </div>
                    <span>&nbsp;</span>
                    <div class="form-group">
                        <strong>接口协议类型:</strong>
                        <select name="interface_type">
                            <option class="glyphicon-option-vertical">http</option>
                            <option>dubbo</option>
                        </select>
                    </div>
                    <span>&nbsp;</span>
                    <div class="form-group">
                        <strong>接口编号:</strong>
                        {{ form.interface_url(id='interfaceurl') }}
                    </div>
                    <span>&nbsp;</span>
                    <div class="form-group">
                        <strong>接口headers:</strong>
                        {{ form.interface_headers (id='interfheader')}}
                        <span style="color: #8D99A8">
                            **dubbo接口这里需要填写入参对象
                        </span>
                    </div>
                    <span>&nbsp;</span>
                    <div class="form-group">
                        <strong>请求方式:</strong>
                        {{ form.interface_meth(id='interfacemeth') }}
                    </div>
                    <span>&nbsp;</span>
                    <div class="form-group" >
                        <strong>请求参数:</strong>
                        {{ form.interface_can (id='interfacedata')}}
                    </div>
                    <span>&nbsp;</span>
                    <div class="form-group" >
                        <strong>请求预期:</strong>
                        {{ form.interface_rest(id='interfaceyuqi') }}
                    </div>
                    <span>&nbsp;</span>
                    <div class="form-group">
                        <strong>是否保存测试结果:</strong>
                        {{ form.save(id='jieguoshifou') }}
                    </div>
                    <div class="form-group">
                        <p>
                            <strong>请选择依赖接口:</strong>
                            <select id="jiekou" name="jiekou">
                            </select>
                        </p>
                        <strong>从依赖接口中获取参数：</strong>
                        <input type="text" name="yilaicanshu" placeholder="请输入要依赖接口测试结果中的数据">
                        <span style="color: rebeccapurple"> *这里的接口如果没有依赖请不要选择添加</span>
                    </div>
                    <div class="form-group">
                        <strong>是否校验数据库:</strong>
                        <input type="radio" name="database" id="database" onclick="qidong()">
                        <div id="shujuku" style="display: none">
                            <p>
                                <strong>数据库语句：</strong>
                                <input type="text" name="databasesql" placeholder="请输入要查询的数据库语句！">
                            </p>
                            <strong>比较字段：</strong><input type="text" name="databijiao" placeholder="请输入和数据库比对！">
                        </div>
                    </div>
                    <button type="submit" class="am-btn am-btn-primary" >添加</button>
                </div>
            </form>
        </div></div>
{%endblock%}
{% block js %}
    <script language="JavaScript">
        function yilai() {
            var pddd=$("input[name='project']:checked").val();
            if (pddd==undefined){
                return;
            };
            $.ajax({
                url:'{{ url_for('getyongli') }}',
                type:'POST',
                data:pddd,
                contentType: 'application/json; charset=UTF-8',
                processData:false,
                success:function(testyong){
                    if(testyong['code']==200){
                        xuanze=testyong['data'];
                        var xuanz=$('#jiekou');
                        xuanz.empty();
                        xuanz.append("<option id='ceshiurls' > 请选择依赖接口</option>")
                        for (var i=0;i<xuanze.length;i++){
                            var url=xuanze[i];
                            xuanz.append("<option id='ceshiurls'>  " + url+"</option>");
                        }
                    }else {
                        alert(testyong['msg'])
                    }
                }
            })
        }
        function qidong() {
            var d=document.getElementById('database');
            var database=document.getElementById('shujuku');
            if (d.checked==true){
                database.style.display='';
            }else {
                database.style.display='none';
            }
        }
    </script>
{% endblock %}